package com.hospicpc.demos.utils;


import org.springframework.web.client.RestTemplate;

public class HttpUtils {

    /**
     * 通过code获取openid
     * @param code
     * @return
     */
    public static String getOpenidByCode(String code) {
        String APPID = "wx5e13ad5d9816514a";
        String SECRET = "a1c885a76f11e4e2513badf16ddd14d2";
        String JSCODE = code;
        System.out.println(code);
        String authorization_code = "authorization_code";
        RestTemplate restTemplate = new RestTemplate();
        String url = "https://api.weixin.qq.com/sns/jscode2session?appid="+APPID+"&secret="+SECRET+"&js_code="+JSCODE+"&grant_type="+authorization_code;
        String str = restTemplate.getForObject(url, String.class);
        System.out.println(str);
        return str;
    }

}